// pages/nicheng/nicheng.js
const {newname} =require('../../util/api')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    nickname:"",
    imgUrls:""

  },
  changgeimg(){
    let that=this
    
    wx.chooseMedia({
      count:1,
      mediaType:['image'],
      sourceType:['album', 'camera'],
      success(res) {
       
        
        that.setData({
          imglist:res.tempFiles[0]
        })
        
        wx.uploadFile({
          filePath: res.tempFiles[0].tempFilePath,
          name: 'file',
          url: 'https://anjingbao.anjingbao.net/prod-api/api/common/appUpload',
          success (res){
            
            let jsonS = JSON.parse(res.data)
            console.log(jsonS)
            that.setData({
              imgUrls:jsonS.fileName 
            })
            let p={
              memberId:wx.getStorageSync('memberId'),
              nickName:wx.getStorageSync('nickName'),
              avatarUrl:jsonS.fileName
            }
            newname(p).then(res=>{
              console.log(res)
            })
            wx.setStorageSync('imgUrls', that.data.imgUrls)
          }
        })
      }

  })},
  nameinput(e){
  this.setData({
    nickname:e.detail.value
  })
    
  },
  handtap(){
    
      
      
      let p={
        memberId:wx.getStorageSync('memberId'),
        nickName:this.data.nickname,
        avatarUrl:this.data.imgUrls
      }
      
      newname(p).then(res=>{
        if(res.code==200){

          wx.setStorageSync('nickName', this.data.nickname)
          wx.navigateBack({
            delta: 1,
          })
        }
      
        
      })
      
    
    // wx.switchTab({
    //   url: '/pages/center/center',
    // })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
console.log(options)
this.setData({
  nickname:options.name
})
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.setData({
      phone:wx.getStorageSync('phone'),
      imgUrls:wx.getStorageSync('imgUrls')
    })

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
    return {
      title: '分享小程序',
      imageUrl: 'https://anjingbao.anjingbao.net/profile/upload/renwufenxianginfo.jpg',
      path:"/pages/shouye/shouye",//当前页面 path ，必须是以 / 开头的完整路径
      success: (res) => {
        console.log("转发成功", res);
      },
      fail: (res) => {
        console.log("转发失败", res);
      }
    }
  }
})